<template>
  <div class="ele-body">
    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="relayId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          :scroll="{ x: 'max-content' }"
        >
        </ele-pro-table>
      </a-card>
    </div>
  </div>
</template>

<script>
import {DeviceSprayCameraGroupRelayTaskApi} from "@/api/property/spraycamera/DeviceSprayCameraGroupRelayTaskApi";
import { message } from 'ant-design-vue';
export default {
  name: 'DeviceManagerdeviceCameraGroupmanagerRelayTask',
  props: {
    data: Object
  },
  async mounted() {
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '开始调度时间',
          dataIndex: 'startAt'
        },
        {
          title: '实际配置开始时间',
          dataIndex: 'realStartAt'
        },
        {
          title: '动作',
          dataIndex: 'action',
          customRender : function(row) {
            if (row.text == 1) {
              return "开始喷淋";
            } else if (row.text == 2) {
              return "结束喷淋";
            }
          }
        },
        {
          title: '调度状态',
          dataIndex: 'status',
          customRender : function(row) {
            if (row.text == 2) {
              return "成功";
            } else if (row.text == 4) {
              return "失败";
            } else {
              return "未执行";
            }
          }
        },
        {
          title: '错误信息',
          dataIndex: 'errorMsg'
        },
        {
          title: '执行状态',
          dataIndex: 'isProcessed',
          customRender : function(row) {
            if (row.text == 1) {
              return "已执行";
            } else {
              return "未执行";
            }
          },
        },
        {
          title: '实际配置记录ID',
          dataIndex: 'logId'
        },
      ],
      // 表格搜索条件
      where: {
        oxtallId : this.data.oxtallId
      },
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false
    };
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2025/03/13 19:52
     */
    reload() {
      this.selection = [];
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2025/03/13 19:52
     */
    reset() {
      this.oxtallId = this.data.oxtallId;
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2025/03/13 19:52
     */
    async remove(row) {
      const result = await DeviceSprayCameraGroupRelayTaskApi.delete({ relayId: row.relayId });
      message.success(result.message);
      this.reload();
    },

    /**
     * 打开新增或编辑弹窗
     *
     * @author cancan
     * @date 2025/03/13 19:52
     */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    datasource({ page, limit, where, orders }) {
      return DeviceSprayCameraGroupRelayTaskApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    },
  }
};
</script>
